package cn.tedu._06interceptor.config;

import cn.tedu._06interceptor.interceptors.MyInterceptor1;
import cn.tedu._06interceptor.interceptors.MyInterceptor2;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 注册拦截器: 实现WebMvcConfigurer接口
 * 1. 创建配置类,实现WebMvcConfigurer接口
 * 2. 在配置类中重写addInterceptors方法,添加拦截器对象
 */
@Configuration
public class MvcConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
//        添加拦截器对象
//        策略1:
//        拦截所有请求
//        registry.addInterceptor(new MyInterceptor1());
//
//        策略2:
//        拦截指定请求, 比如拦截 / users / login请求
//        registry.addInterceptor(new MyInterceptor1())
//                .addPathPatterns("/users/login", "users/reg");
//
//        策略3:
//        拦截指定模块的请求, 比如拦截用户模块的所有请求
//        registry.addInterceptor(new MyInterceptor1())
//                .addPathPatterns("/users/**");
//        策略4:
//        排除指定模块的部分请求, 比如:拦截用户模块的所有请求, 但是排除 / users / login
//        registry.addInterceptor(new MyInterceptor1())
//                .addPathPatterns("/users/**")
//                .excludePathPatterns("/users/login");

        registry.addInterceptor(new MyInterceptor1());
        registry.addInterceptor(new MyInterceptor2());

    }


}
